import { observable, action } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';
import * as API_MONITOR from '../../apis/odocApi';
import SearchStore from './SearchStore';

const getLabel = WeaLocaleProvider.getLabel;

export default class BaseListStore {
  @observable topTitle = '';

  // Tab对象 静态数据
  @observable S_TAB = {
    KEYPARAM: 'viewcondition', // tab页参数
    COUNTPARAM: 'groupid', // tab页分组字段
    SEARCHTYPE: ['base', 'advanced'], // tab页查询类型
  }

  @observable API_CONDITION = '';
  @observable API_DATALIST = '';
  @observable API_TABCOUNT = '';

  @observable showDropMenu = true;

  // tab页
  @observable tabs = [

  ];

  // tab页统计
  @observable tabsCount = {

  }

  // 当前选中tab
  @observable selectedTab = 1;

  @observable selectedRows = [];

  @observable searchStore = new SearchStore();

  @observable doForward = false;
  @observable forwardParams = {};

  @action
  setTopTitle = (topTitle) => {
    this.topTitle = topTitle;
  }

  setTabs = (tabs) => {
    this.tabs = tabs;
  }

  setTabsCount = (tabsCount) => {
    this.tabsCount = tabsCount;
  }

  setSelectedTab = (selectedTab) => {
    this.selectedTab = selectedTab;
  }

  setSelectedRows = (selectedRows) => {
    this.selectedRows = selectedRows;
  }

  setDoForward = (doForward) => {
    this.doForward = doForward;
  }

  setForwardParams = (forwardParams) => {
    this.forwardParams = forwardParams;
  }

  constructor() {
    this.buildTabs = this.buildTabs.bind(this);
  }

  // 构建tab页
  buildTabs(module, params = {}) {
    if (this.API_TABCOUNT == '') {
      return;
    }
    API_MONITOR.flexibleCallApi(this.API_TABCOUNT, params).then((data) => {
      let tabArr = data.datalist;
      let tabs = [];
      let tabsCount = {};
      tabArr.forEach((element) => {
        let tab = {
          color: '#000000',
          showcount: true,
          groupid: element.officalType,
          title: element.title,
          viewcondition: element.officalType,
        };
        tabs.push(tab);
        tabsCount[element.officalType] = element.count;
      });
      this.setTabs(tabs);
      this.setTabsCount(tabsCount);
    });
  }

  getSearchsBaseValue() {
    return '';
  }

  setSearchsBaseValue() {

  }

  getTopBtns() {
    return ([]);
  }

  /* doSearch(params){

  }

  buildSearchCondition(params){

  } */

  handleSelectedRowsChange() {

  }

  getLabel2(id, label) {
    return getLabel(id, label);
  }

  getColumns() {

  }
}
